package com.cisetech.service.impl;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cisetech.mapper.bobocai.LUserMapper;
import com.cisetech.service.PasswordService;
import com.cisetech.util.CreateMD5;
import com.cisetech.vo.bobocai.LUser;

@Service
public class PasswordServiceImpl implements PasswordService {
	@Autowired
	LUserMapper userMapper;
	
	
	@Override
	public String updatePass(LUser user,String newPass,String newpassT,HttpServletRequest request) {
		Logger log = Logger.getLogger(PasswordServiceImpl.class);
		if(user==null){
			return "4";
		}
		if(user.getName()==null || "".equals(user.getName())){
			return "5";
		}
		if(user.getPassword()==null || "".equals(user.getPassword())){
			return "6";
		}
		if(newPass==null || "".equals(newPass)){
			return "7";
		}
		if(newpassT==null || "".equals(newpassT)){
			return "8";
		}
		if(!newPass.equals(newpassT)){
			return "3";
		}
		LUser u = (LUser) request.getSession().getAttribute("luser");
		if(u == null){
			return "9";
		}
		if(!u.getPassword().equals(CreateMD5.getMd5(user.getPassword()))){
			return "1";
		}
		if(user.getPassword().equals(newPass)){
			return "2";
		}
		user.setId(u.getId());
		user.setPassword(CreateMD5.getMd5(newPass));
		try {
			userMapper.updatePass(user);
		} catch (Exception e) {
			log.debug(e.getLocalizedMessage());
			return "10";
		}
		
		return "0";
	}

}
